/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2008 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission 
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License 
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably 
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#ifndef INCL_FUN_ALARM
#define INCL_FUN_ALARM
    
#include "base/util/StringBuffer.h"
#include "PIMItem.h"
#include "Date.h"
#include "Timezone.h"
#include "TimeUtils.h"
#include "constants.h"

using namespace Funambol;

/**
* The class represent an alarm of an appointment. It is consider to have 2 main alarm, the primary and the secondary.
* Usually the alarm can be filled using the primaryAlarm and secondaryAlarm fields and then, calling
* the method completeFields, it fields the remaining primary_minBeforeStart and secondary_MinBeforeStart. At the same
* way, filling the primary_minBeforeStart and secondary_MinBeforeStart it fills the primaryAlarm and secondaryAlarm.  
*/

class Alarm {
    
private:
        
    /**
     * The primaryAlarm of the event. It is a date and it represent an alarm for the user before the app start.
     * Usually the format is YYYYmmddTHHmmss for normal event 
     */
    Date primaryAlarm;
    
    /**
     * The secondaryAlarm of the event. It is a date and it represent an alarm for the user before the app start.
     * Usually the format is YYYYmmddTHHmmss for normal event 
     */
    Date secondaryAlarm;
    
    /**
    * The reminder is set(true) or not (false);
    */    
    long primary_minBeforeStart;
    
    /**
     * The reminder is set(true) or not (false);
     */    
    long secondary_minBeforeStart;
    
public:
    
    Alarm() {
        primaryAlarm.setDate(EMPTY_DATE);        
        secondaryAlarm.setDate(EMPTY_DATE);        
        primary_minBeforeStart = UNUSED_LONG_VALUE; // default null value
        secondary_minBeforeStart = UNUSED_LONG_VALUE;  // default null value
    }
    
    ~Alarm() {}
    
    /**
     * When the alarm is set by date, the minutes is set to 0. So if the minutes are 0 the conversion
     * is done by the difference between the dates.
     */ 
    void setPrimaryAlarm(Date& d);
    Date& getPrimaryAlarm() { return primaryAlarm; }
    
    /**
     * When the alarm is set by date, the minutes is set to 0. So if the minutes are 0 the conversion
     * is done by the difference between the dates.
     */ 
    void setSecondaryAlarm(Date& d);
    Date& getSecondaryAlarm() { return secondaryAlarm; }
    
    /**
     * If the minutes is greater then 0, the value is used to calculate the date
     */
    void setPrimary_minBeforeStart(long d) { primary_minBeforeStart = d; }
    void setPrimary_secBeforeStart(long d) { primary_minBeforeStart = d / 60; }
    void setPrimary_secBeforeStart(const char* d) { setPrimary_secBeforeStart(atol(d)); }
    void setPrimary_minBeforeStart(const char* d) { setPrimary_minBeforeStart(atol(d)); }
    
    long getPrimary_minBeforeStart() { return primary_minBeforeStart; }  
    long getPrimary_secBeforeStart() { return primary_minBeforeStart * 60; }  
    StringBuffer getPrimary_minBeforeStart(void*);  
    StringBuffer getPrimary_secBeforeStart(void*);
    
    
    /**
     * When the alarm is set by date, the minutes is set to 0. So if the minutes are 0 the conversion
     * is done by the difference between the dates.
     */ 
    void setSecondary_minBeforeStart(long d) { secondary_minBeforeStart = d; }
    void setSecondary_secBeforeStart(long d) { secondary_minBeforeStart = d / 60; }
    void setSecondary_secBeforeStart(const char* d) { setSecondary_secBeforeStart(atol(d)); }
    void setSecondary_minBeforeStart(const char* d) { setSecondary_minBeforeStart(atol(d)); }
    
    
    long getSecondary_minBeforeStart() { return secondary_minBeforeStart; }
    long getSecondary_secBeforeStart() { return (long)secondary_minBeforeStart * 60; }
    StringBuffer getSecondary_minBeforeStart(void*); 
    StringBuffer getSecondary_secBeforeStart(void*);
    /**
     * It complete the corrispondent fields minutes or date based on fillMinutes property.
     * If the *_minBeforeStart == 0 the startDate and *Alarm are used to calculate
     * the corrispondent value of minutes. 
     * If the *_minBeforeStart != 0 then the startDate and *_minBeforeStart are used to
     * calculate the *Alarm.
     */
    void completeFields(Date& startDate);
       
};

#endif

